Dynomotion

Group: DynoMotion Message: 12212 From: peterpan1e6 Date: 9/6/2015
Subject: Controlling 2 Machines

Hi, I am controlling 2 independent machines with KFlop and KStep. There are 2 C programs running on 2 separate threads. Currently I am starting the programs manually by clicking on buttons set to start the programs.


I read somewhere that it is possible to set the C program on thread 7 to run on startup.


How can I start the second program running on another thread on startup? Is it possible to start anoh program from the one running in thread 7?

Group: DynoMotion Message: 12214 From: TKSOFT Date: 9/6/2015
Subject: Re: Controlling 2 Machines
Hi Eon,

I assume you are using KMotionCNC.  The later test Version allow an Application Startup Action to compile/download execute one C Program into any Thread.

There isn't a direct way compile/download execute two programs into two threads.   Are you sure you need two Threads?   Often you can code as a state machine and have one thread perform multiple operations.

A workaround can be to have the first C Program "push" a User Button to launch the second Thread.  The User Button may be hidden.

HTH
Regards
TK

Group: DynoMotion Message: 12233 From: Eon de Koker Date: 9/9/2015
Subject: Re: Controlling 2 Machines

Hi, Thanks

 

-          Any pointers on where to find the Application Startup Action?

-          Both C programs run in while loops which blocks waiting for inputs. Any pointers on how to combine these so the one waiting state is not stopping the other control loop? Can one toggle between the two loops every time the Tread is run?

Regards

 

Eon

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com]
Sent: Sunday, 06 September 2015 23:38
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Controlling 2 Machines

 

 

Hi Eon,

 

I assume you are using KMotionCNC.  The later test Version allow an Application Startup Action to compile/download execute one C Program into any Thread.



There isn't a direct way compile/download execute two programs into two threads.   Are you sure you need two Threads?   Often you can code as a state machine and have one thread perform multiple operations.



A workaround can be to have the first C Program "push" a User Button to launch the second Thread.  The User Button may be hidden.



HTH

Regards

TK

 


From: "eondekoker@... [DynoMotion]" <DynoMotion@yahoogroups.com>
To: DynoMotion@yahoogroups.com
Sent: Sunday, September 6, 2015 2:02 PM
Subject: [DynoMotion] Controlling 2 Machines

 

 

Hi, I am controlling 2 independent machines with KFlop and KStep. There are 2 C programs running on 2 separate threads. Currently I am starting the programs manually by clicking on buttons set to start the programs.



I read somewhere that it is possible to set the C program on thread 7 to run on startup.



How can I start the second program running on another thread on startup? Is it possible to start anoh program from the one running in thread 7?

 

Group: DynoMotion Message: 12234 From: Tom Kerekes Date: 9/9/2015
Subject: Re: Controlling 2 Machines
Hi Eon,

For executing an "Action" on startup see the help (Prog Startup):

Regarding having one Thread or loop doing multiple things: there are various approaches depending on how involved the things you are trying to do simultaneously.  If all you need to do is something relatively instantaneous (ie disable something when an input changes)  it is relatively easy.    In this case just make one loop that checks multiple things.  See the ExternalButtons.c example.  It uses a helper function (Debounce) and a few variables to keep track of if the input changed and for how long and returns a code to tell you when the input changed without ever waiting for anything (which would block other activities in the loop).

The example ServiceToolChange.c is an example of how to perform a multistep process without ever blocking.  This program is written in the form of a "State Machine".  This is a bit more complicated than a simple sequential program that executes in a linear fashion.  The advantage of this approach is that it doesn't need its own Thread to execute a sequence that might take a while.  Also this approach works if you want to have external tool change buttons to invoke the sequence (not necessarily form GCode or KMotionCNC).  The advantage of a "state machine" approach is that it always keeps track of its state (exactly what it was doing) in a state variable and other variables.  This allows the processor to go away and do other things at the same time (watchdog, pendent, switch inputs, spindle, etc...) and then come back, realize what they were doing, and resume what they were doing for a bit before again going away.  Most programs like a tool changer program will spend 99.99% of its time simply waiting for something to happen.  These are usually: #1 waiting for a motion to complete, #2 waiting for an input to change, or #3 waiting for a delay to pass.   So the idea is basically to remember what state we were in.  For example waiting for a delay time to go by.  Let's say we want to bake a cake for an hour. A sequential program would: turn on the oven, delay(sleep) for an hour doing nothing, then turn off the oven.  A state driven program would turn on the oven, then look at the clock, add 1 hr, and write down that as the final time (ToolTime).  Now he is free to go away, run other errands, as long as he comes back every minute or two and checks the clock (Time_sec()) to see if it is past the final time.  If not just exit and do nothing.  But if it is past time, then turn off the oven and switch states to something else.

HTH
Regards
TK